package com.pengshun.modules.api.petrol;

import com.pengshun.modules.api.coal.validator.First;
import com.pengshun.modules.api.petrol.service.PetrolStationService;
import com.pengshun.modules.api.petrol.service.dto.JyPetrolStationConditionDto;
import com.pengshun.modules.api.petrol.service.dto.JyPetrolStationProductDetilDto;
import com.pengshun.modules.api.petrol.service.dto.JyPetrolStationProductListDto;
import com.pengshun.modules.api.petrol.service.dto.JyPetrolStationTypeDto;
import com.pengshun.modules.api.petrol.service.para.JyPetrolStationProductListPara;
import com.pengshun.modules.common.BaseResult;
import com.pengshun.modules.common.PagePara;
import com.pengshun.modules.domain.JyPetrolStationGun;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author luoligang
 * @create 2021/6/28
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "加油管理")
@RequestMapping("/api/petrol")
public class PetrolStationController {

    private final PetrolStationService petrolStationService;

    @ApiOperation(value = "加油列表")
    @GetMapping(value = "/list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "longitude", value = "经度", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "latitude", value = "纬度", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "distance", value = "默认不传 距离", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "stationId", value = "默认不传 类型id", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "sort", value = "默认不传 1距离 2价格", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = " 名称", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "brandId", value = "默认不传 品牌id", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "条数", dataType = "int", required = true, paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 0, message = "OK", response = JyPetrolStationProductListDto.class)
    })
    public BaseResult product(@ApiIgnore @Validated(value = {First.class}) PagePara page, JyPetrolStationProductListPara para) {
        BaseResult res = petrolStationService.list(page, para);
        return res;

    }

    @ApiOperation(value = "加油站详情")
    @GetMapping(value = "/detil")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "petrolStationProductId", value = "加油站商品id", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "longitude", value = "经度", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "latitude", value = "纬度", dataType = "double", required = true, paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 0, message = "OK", response = JyPetrolStationProductDetilDto.class)
    })
    public BaseResult detil(@ApiIgnore JyPetrolStationProductListPara para) {
        BaseResult res = petrolStationService.detil(para);
        return res;

    }


    @ApiOperation(value = "加油站类型价格")
    @GetMapping(value = "/type")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "petrolStationId", value = "加油站id", dataType = "int", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 0, message = "OK", response = JyPetrolStationTypeDto.class)
    })
    public BaseResult type(@ApiIgnore JyPetrolStationProductListPara para) {
        BaseResult res = petrolStationService.type(para);
        return res;

    }

    @ApiOperation(value = "加油站首页条件")
    @GetMapping(value = "/condition")
    @ApiResponses({
            @ApiResponse(code = 0, message = "OK", response = JyPetrolStationConditionDto.class)
    })
    public BaseResult condition() {
        BaseResult res = petrolStationService.condition();
        return res;
    }

    @ApiOperation(value = "枪号列表查询")
    @GetMapping(value = "/gun")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "petrolStationProductId", value = "加油站id", dataType = "int", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 0, message = "OK", response = JyPetrolStationGun.class)
    })
    public BaseResult gun(Long petrolStationProductId) {
        BaseResult res = petrolStationService.guns(petrolStationProductId);
        return res;

    }


}
